//
//  LRFamousTableViewCell.m
//  本地生活圈
//
//  Created by admin on 15/8/13.
//  Copyright (c) 2015年 懒人. All rights reserved.
//

#import "LRFamousTableViewCell.h"
#import "LRFamousCollectionViewCell.h"
#import "LRHomeModel.h"
@interface LRFamousTableViewCell ()<UICollectionViewDataSource,UICollectionViewDelegate>
@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
@property (weak, nonatomic) IBOutlet UICollectionViewFlowLayout *flowLayout;

@end
@implementation LRFamousTableViewCell

static NSString *identifierID = @"LRFamousCollectionViewCell";
- (void)awakeFromNib {
    // Initialization code
    
    // 初始化
    [self.collectionView registerNib:[UINib nibWithNibName:identifierID bundle:nil] forCellWithReuseIdentifier:identifierID];
    self.collectionView.backgroundColor = [UIColor whiteColor];
    // 不能滚动
    self.collectionView.scrollEnabled = NO;
    // 只能显示4个
    self.flowLayout.itemSize = CGSizeMake(self.bounds.size.width / 2, self.bounds.size.height / 2);
    // 设置间隔
    self.flowLayout.minimumLineSpacing = 0;
    self.flowLayout.minimumInteritemSpacing = 0;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setFamous:(LRFamousModel *)famous
{
    _famous = famous;
    [self.collectionView reloadData];
}

#pragma mark - UICollectionView 数据源&代理方法实现
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 4;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{

    LRFamousCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifierID forIndexPath:indexPath];
    cell.list = self.famous.list[indexPath.row];
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    if ([self.delegate respondsToSelector:@selector(didGotoDetailWithfamouslist:)])
    {
        [self.delegate didGotoDetailWithfamouslist:self.famous.list[indexPath.row]];
    }
    
}

@end
